'use strict';
const {getDefaultModelConfig} = require("../../utils/common");
const { formatDecimal } = require("../../utils/index");
// 官方参考价格表
module.exports = app => {
    const { STRING, INTEGER, BIGINT, DECIMAL, DATE } = app.Sequelize;
    return app.model.define(
        'Dish',
        {
            id: { type: BIGINT, primaryKey: true, autoIncrement: true },
            name: { type: STRING(255), allowNull: false, comment: '菜品名称' },
            category: { type: STRING(100), allowNull: false, comment: '菜品分类' },
            unit: { type: STRING(50), allowNull: false, comment: '单位' },
            base_price: { 
                type: DECIMAL(10, 2), 
                allowNull: false, 
                comment: '官方参考价格',
                get() {
                    return formatDecimal(this.getDataValue('base_price'));
                }
             },
            monthly_bidding_id: { type: BIGINT, allowNull: false, comment: '月度招标ID' },
            status: { type: INTEGER, defaultValue: 1, comment: '状态 1:有效 0:无效' },
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'dish',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
}; 
